package com.ouyu.tech.ifelsereplace.test;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;


@Configuration
@Component
@EnableConfigurationProperties({DataEnum.class})
public class LoadEnumData {
    private static LoadEnumData loadEnumData =null;
    private static final Map<String,Condition> instanceLoad =new HashMap<>();//保存的对象实例
    private synchronized static final LoadEnumData getLoadEnumData(){
        if(loadEnumData==null){
            loadEnumData =new LoadEnumData();
        }
        return loadEnumData;
    }
    public static LoadEnumData getSingleInstance(){
        if(loadEnumData == null){
            getLoadEnumData();
        }
        return loadEnumData;
    }

    public void getConditionContext(String type){
       Condition condition= instanceLoad.get(type);
       if(condition == null){
           throw new RuntimeException("没有对应的条件对象可取！");
       }
       condition.getConditionContext();
    }
    protected void setInstanceLoad(String type,Condition condition){
        instanceLoad.put(type,condition);
    }
}
